Ext.Loader.setConfig({enabled: true});
Ext.Loader.setPath({'Ext.ux' : 'extjs4/ux'});
Ext.define('TS.view.settings.PeriodEndForward',{
	extend: 'Ext.form.Panel',
	border: false,
	bodyPadding:0,
	layout:'anchor',
	alias: 'widget.periodendforward',
	title: '期末结转',
	fieldDefaults:{
		labelAlign:'right',
		labelWidth:40
	},
	initComponent:function() {
		this.items = [
		     {
		    	 html : '<h1 align=center><font color=red>期&ensp;末&ensp;结&ensp;转</font></h1>'
		     },
		     {
					xtype:'fieldset',
			        height:50,
			        width:300,
			        margin:'0 0 0 10',
			        title: '当前期间',
			        layout:'hbox',
					fieldDefaults:{
						labelAlign:'right',
						labelWidth:40
			    	},
			        items:[
		        			{
		                        xtype: 'numberfield',
		                        fieldLabel: '年份',
		                        name:'begYear',
		                        allowDecimals:false,
		                        width:100,
		                        allowBlank: false
		                    },
		        			{
		                        fieldLabel: '期间',
		                        name:'begPeriod',
		                        labelSeparator:null,
		                        xtype: 'numberfield',
		                        width:100,
		                        allowDecimals:false,
		                        allowBlank: false,
		                        minValue:1,
		                        maxValue:12
		                    }
		              ]
				},
				{
					xtype:'fieldset',
			        height:50,
			        width:300,
			        margin:'0 0 0 10',
			        title: '下一期间',
			        layout:'hbox',
					fieldDefaults:{
						labelAlign:'right',
						labelWidth:40
			    	},
					items:[
	                    {
	                        xtype: 'numberfield',
	                        fieldLabel: '年份',
	                        name:'endYear',
	                        allowDecimals:false,
	                        width:100,
	                        allowBlank: false
	                    },
	        			{
	                        fieldLabel: '期间',
	                        name:'endPeriod',
	                        xtype: 'numberfield',
	                        width:100,
	                        allowDecimals:false,
	                        allowBlank: false,
	                        minValue:1,
	                        maxValue:12
	                    }	
                    ]
				},
				{
					xtype: 'button',margin:'10 0 0 10',text:'开始结转',action:'forward',iconCls:'bill-find-button'
				}
		];
		this.callParent(arguments);
	},
	listeners:{
		render:{
			fn:function(form) {
				var curStore = Ext.create('Ext.data.Store', {
				     model: 'TS.model.common.PeriodModel',
				     proxy: {
				         type: 'ajax',
				         url: 'periodendforward/curPeriod.do',
				         reader: {
				             type: 'json',
				             root: ''
				         }
				     }
				});
				var begYear = form.query('numberfield[name=begYear]')[0];
				var begPeriod = form.query('numberfield[name=begPeriod]')[0];
				curStore.load({
					callback: function(records, operation, success) {
						if(success) {
							var mperiod = records[0];
							begYear.setValue(mperiod.get('fyear'));
							begYear.setMinValue(mperiod.get('fyear') - 5);
							begYear.setMaxValue(mperiod.get('fyear') + 5);
							begPeriod.setValue(mperiod.get('period'));
						}
					},
					scope:this
				});
				var nextStore = Ext.create('Ext.data.Store', {
				     model: 'TS.model.common.PeriodModel',
				     proxy: {
				         type: 'ajax',
				         url: 'periodendforward/nextPeriod.do',
				         reader: {
				             type: 'json',
				             root: ''
				         }
				     }
				});
				var endYear = form.query('numberfield[name=endYear]')[0];
				var endPeriod = form.query('numberfield[name=endPeriod]')[0];
				nextStore.load({
					callback: function(records, operation, success) {
						if(success) {
							var nextperiod = records[0];
							endYear.setValue(nextperiod.get('fyear'));
							endYear.setMaxValue(nextperiod.get('fyear') + 5);
							endYear.setMinValue(nextperiod.get('fyear') - 5);
							endPeriod.setValue(nextperiod.get('period'));
						}
					},
					scope:this
				});
			}
		}
	}
});